<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="theme-color" content="#33474d">
	<title>redis 配置 | 失落的乐章</title>
	<link rel="stylesheet" href="/css/style.css" />
	
      <link rel="alternate" href="/atom.xml" title="失落的乐章" type="application/atom+xml">
    
</head>

<body>

	<header class="header">
		<nav class="header__nav">
			
				<a href="/archives" class="header__link">Archive</a>
			
				<a href="/tags" class="header__link">Tags</a>
			
				<a href="/atom.xml" class="header__link">RSS</a>
			
		</nav>
		<h1 class="header__title"><a href="/">失落的乐章</a></h1>
		<h2 class="header__subtitle">技术面前，永远都是学生。</h2>
	</header>

	<main>
		<article>
	
		<h1>redis 配置</h1>
	
	<div class="article__infos">
		<span class="article__date">2017-10-12</span><br />
		
		
			<span class="article__tags">
			  	<a class="article__tag-link" href="/tags/Redis/">Redis</a>
			</span>
		
	</div>

	

	
		<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Redis 的配置文件位于 Redis 安装目录下，文件名为 redis.conf。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;可以通过 <strong>CONFIG</strong> 命令查看或设置配置项。</p>
<h2 id="语法"><a href="#语法" class="headerlink" title="语法"></a>语法</h2><h3 id="Redis-CONFIG-命令格式如下："><a href="#Redis-CONFIG-命令格式如下：" class="headerlink" title="Redis CONFIG 命令格式如下："></a>Redis CONFIG 命令格式如下：</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">redis 127.0.0.1:6379&gt; CONFIG GET CONFIG_SETTING_NAME</div></pre></td></tr></table></figure>
<h3 id="实例"><a href="#实例" class="headerlink" title="实例"></a>实例</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">redis 127.0.0.1:6379&gt; CONFIG GET loglevel</div><div class="line"> </div><div class="line">1) <span class="string">"loglevel"</span></div><div class="line">2) <span class="string">"notice"</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;使用 * 号获取所有配置项：</p>
<h3 id="实例-1"><a href="#实例-1" class="headerlink" title="实例"></a>实例</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div><div class="line">65</div><div class="line">66</div><div class="line">67</div><div class="line">68</div><div class="line">69</div><div class="line">70</div><div class="line">71</div><div class="line">72</div><div class="line">73</div><div class="line">74</div><div class="line">75</div><div class="line">76</div><div class="line">77</div><div class="line">78</div><div class="line">79</div><div class="line">80</div><div class="line">81</div><div class="line">82</div><div class="line">83</div><div class="line">84</div><div class="line">85</div><div class="line">86</div><div class="line">87</div><div class="line">88</div><div class="line">89</div><div class="line">90</div><div class="line">91</div><div class="line">92</div><div class="line">93</div><div class="line">94</div><div class="line">95</div><div class="line">96</div><div class="line">97</div><div class="line">98</div><div class="line">99</div><div class="line">100</div><div class="line">101</div><div class="line">102</div><div class="line">103</div><div class="line">104</div><div class="line">105</div><div class="line">106</div><div class="line">107</div><div class="line">108</div><div class="line">109</div><div class="line">110</div><div class="line">111</div><div class="line">112</div><div class="line">113</div><div class="line">114</div><div class="line">115</div><div class="line">116</div><div class="line">117</div><div class="line">118</div></pre></td><td class="code"><pre><div class="line">redis 127.0.0.1:6379&gt; CONFIG GET *</div><div class="line"></div><div class="line">1) <span class="string">"dbfilename"</span></div><div class="line">2) <span class="string">"dump.rdb"</span></div><div class="line">3) <span class="string">"requirepass"</span></div><div class="line">4) <span class="string">""</span></div><div class="line">5) <span class="string">"masterauth"</span></div><div class="line">6) <span class="string">""</span></div><div class="line">7) <span class="string">"unixsocket"</span>          </div><div class="line">8) <span class="string">""</span></div><div class="line">9) <span class="string">"logfile"</span></div><div class="line">10) <span class="string">""</span></div><div class="line">11) <span class="string">"pidfile"</span></div><div class="line">12) <span class="string">"/var/run/redis.pid"</span></div><div class="line">13) <span class="string">"maxmemory"</span></div><div class="line">14) <span class="string">"0"</span></div><div class="line">15) <span class="string">"maxmemory-samples"</span></div><div class="line">16) <span class="string">"3"</span></div><div class="line">17) <span class="string">"timeout"</span></div><div class="line">18) <span class="string">"0"</span></div><div class="line">19) <span class="string">"tcp-keepalive"</span></div><div class="line">20) <span class="string">"0"</span></div><div class="line">21) <span class="string">"auto-aof-rewrite-percentage"</span></div><div class="line">22) <span class="string">"100"</span></div><div class="line">23) <span class="string">"auto-aof-rewrite-min-size"</span></div><div class="line">24) <span class="string">"67108864"</span></div><div class="line">25) <span class="string">"hash-max-ziplist-entries"</span></div><div class="line">26) <span class="string">"512"</span></div><div class="line">27) <span class="string">"hash-max-ziplist-value"</span></div><div class="line">28) <span class="string">"64"</span></div><div class="line">29) <span class="string">"list-max-ziplist-entries"</span></div><div class="line">30) <span class="string">"512"</span></div><div class="line">31) <span class="string">"list-max-ziplist-value"</span></div><div class="line">32) <span class="string">"64"</span></div><div class="line">33) <span class="string">"set-max-intset-entries"</span></div><div class="line">34) <span class="string">"512"</span></div><div class="line">35) <span class="string">"zset-max-ziplist-entries"</span></div><div class="line">36) <span class="string">"128"</span></div><div class="line">37) <span class="string">"zset-max-ziplist-value"</span></div><div class="line">38) <span class="string">"64"</span></div><div class="line">39) <span class="string">"hll-sparse-max-bytes"</span></div><div class="line">40) <span class="string">"3000"</span></div><div class="line">41) <span class="string">"lua-time-limit"</span></div><div class="line">42) <span class="string">"5000"</span></div><div class="line">43) <span class="string">"slowlog-log-slower-than"</span></div><div class="line">44) <span class="string">"10000"</span></div><div class="line">45) <span class="string">"latency-monitor-threshold"</span></div><div class="line">46) <span class="string">"0"</span></div><div class="line">47) <span class="string">"slowlog-max-len"</span></div><div class="line">48) <span class="string">"128"</span></div><div class="line">49) <span class="string">"port"</span></div><div class="line">50) <span class="string">"6379"</span></div><div class="line">51) <span class="string">"tcp-backlog"</span></div><div class="line">52) <span class="string">"511"</span></div><div class="line">53) <span class="string">"databases"</span></div><div class="line">54) <span class="string">"16"</span></div><div class="line">55) <span class="string">"repl-ping-slave-period"</span></div><div class="line">56) <span class="string">"10"</span></div><div class="line">57) <span class="string">"repl-timeout"</span></div><div class="line">58) <span class="string">"60"</span></div><div class="line">59) <span class="string">"repl-backlog-size"</span></div><div class="line">60) <span class="string">"1048576"</span></div><div class="line">61) <span class="string">"repl-backlog-ttl"</span></div><div class="line">62) <span class="string">"3600"</span></div><div class="line">63) <span class="string">"maxclients"</span></div><div class="line">64) <span class="string">"4064"</span></div><div class="line">65) <span class="string">"watchdog-period"</span></div><div class="line">66) <span class="string">"0"</span></div><div class="line">67) <span class="string">"slave-priority"</span></div><div class="line">68) <span class="string">"100"</span></div><div class="line">69) <span class="string">"min-slaves-to-write"</span></div><div class="line">70) <span class="string">"0"</span></div><div class="line">71) <span class="string">"min-slaves-max-lag"</span></div><div class="line">72) <span class="string">"10"</span></div><div class="line">73) <span class="string">"hz"</span></div><div class="line">74) <span class="string">"10"</span></div><div class="line">75) <span class="string">"no-appendfsync-on-rewrite"</span></div><div class="line">76) <span class="string">"no"</span></div><div class="line">77) <span class="string">"slave-serve-stale-data"</span></div><div class="line">78) <span class="string">"yes"</span></div><div class="line">79) <span class="string">"slave-read-only"</span></div><div class="line">80) <span class="string">"yes"</span></div><div class="line">81) <span class="string">"stop-writes-on-bgsave-error"</span></div><div class="line">82) <span class="string">"yes"</span></div><div class="line">83) <span class="string">"daemonize"</span></div><div class="line">84) <span class="string">"no"</span></div><div class="line">85) <span class="string">"rdbcompression"</span></div><div class="line">86) <span class="string">"yes"</span></div><div class="line">87) <span class="string">"rdbchecksum"</span></div><div class="line">88) <span class="string">"yes"</span></div><div class="line">89) <span class="string">"activerehashing"</span></div><div class="line">90) <span class="string">"yes"</span></div><div class="line">91) <span class="string">"repl-disable-tcp-nodelay"</span></div><div class="line">92) <span class="string">"no"</span></div><div class="line">93) <span class="string">"aof-rewrite-incremental-fsync"</span></div><div class="line">94) <span class="string">"yes"</span></div><div class="line">95) <span class="string">"appendonly"</span></div><div class="line">96) <span class="string">"no"</span></div><div class="line">97) <span class="string">"dir"</span></div><div class="line">98) <span class="string">"/home/deepak/Downloads/redis-2.8.13/src"</span></div><div class="line">99) <span class="string">"maxmemory-policy"</span></div><div class="line">100) <span class="string">"volatile-lru"</span></div><div class="line">101) <span class="string">"appendfsync"</span></div><div class="line">102) <span class="string">"everysec"</span></div><div class="line">103) <span class="string">"save"</span></div><div class="line">104) <span class="string">"3600 1 300 100 60 10000"</span></div><div class="line">105) <span class="string">"loglevel"</span></div><div class="line">106) <span class="string">"notice"</span></div><div class="line">107) <span class="string">"client-output-buffer-limit"</span></div><div class="line">108) <span class="string">"normal 0 0 0 slave 268435456 67108864 60 pubsub 33554432 8388608 60"</span></div><div class="line">109) <span class="string">"unixsocketperm"</span></div><div class="line">110) <span class="string">"0"</span></div><div class="line">111) <span class="string">"slaveof"</span></div><div class="line">112) <span class="string">""</span></div><div class="line">113) <span class="string">"notify-keyspace-events"</span></div><div class="line">114) <span class="string">""</span></div><div class="line">115) <span class="string">"bind"</span></div><div class="line">116) <span class="string">""</span></div></pre></td></tr></table></figure>
<h2 id="编辑配置"><a href="#编辑配置" class="headerlink" title="编辑配置"></a>编辑配置</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;可以通过修改 redis.conf 文件或使用 <strong>CONFIG set</strong> 命令来修改配置。</p>
<h3 id="语法-1"><a href="#语法-1" class="headerlink" title="语法"></a>语法</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>CONFIG SET</strong> 命令基本语法：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">redis 127.0.0.1:6379&gt; CONFIG SET CONFIG_SETTING_NAME NEW_CONFIG_VALUE</div></pre></td></tr></table></figure>
<h3 id="实例-2"><a href="#实例-2" class="headerlink" title="实例"></a>实例</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line">redis 127.0.0.1:6379&gt; CONFIG SET loglevel <span class="string">"notice"</span></div><div class="line">OK</div><div class="line">redis 127.0.0.1:6379&gt; CONFIG GET loglevel</div><div class="line"> </div><div class="line">1) <span class="string">"loglevel"</span></div><div class="line">2) <span class="string">"notice"</span></div></pre></td></tr></table></figure>
<h2 id="参数说明"><a href="#参数说明" class="headerlink" title="参数说明"></a>参数说明</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;redis.conf 配置项说明如下：</p>
<ol>
<li>Redis默认不是以守护进程的方式运行，可以通过该配置项修改，使用yes启用守护进程</li>
</ol>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">daemonize no</div></pre></td></tr></table></figure>
<ol>
<li>当Redis以守护进程方式运行时，Redis默认会把pid写入/var/run/redis.pid文件，可以通过pidfile指定</li>
</ol>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">pidfile /var/run/redis.pid</div></pre></td></tr></table></figure>
<ol>
<li>指定Redis监听端口，默认端口为6379，作者在自己的一篇博文中解释了为什么选用6379作为默认端口，因为6379在手机按键上MERZ对应的号码，而MERZ取自意大利歌女Alessia Merz的名字</li>
</ol>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">port 6379</div></pre></td></tr></table></figure>
<ol>
<li>绑定的主机地址</li>
</ol>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="built_in">bind</span> 127.0.0.1</div></pre></td></tr></table></figure>
<p>5.当 客户端闲置多长时间后关闭连接，如果指定为0，表示关闭该功能</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">timeout 300</div></pre></td></tr></table></figure>
<ol>
<li>指定日志记录级别，Redis总共支持四个级别：debug、verbose、notice、warning，默认为verbose</li>
</ol>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">loglevel verbose</div></pre></td></tr></table></figure>
<ol>
<li>日志记录方式，默认为标准输出，如果配置Redis为守护进程方式运行，而这里又配置为日志记录方式为标准输出，则日志将会发送给/dev/null</li>
</ol>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">logfile stdout</div></pre></td></tr></table></figure>
<ol>
<li>设置数据库的数量，默认数据库为0，可以使用SELECT <dbid>命令在连接上指定数据库id</dbid></li>
</ol>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">databases 16</div></pre></td></tr></table></figure>
<ol>
<li>指定在多长时间内，有多少次更新操作，就将数据同步到数据文件，可以多个条件配合</li>
</ol>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">save &lt;seconds&gt; &lt;changes&gt;</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Redis默认配置文件中提供了三个条件：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">save 900 1</div><div class="line">save 300 10</div><div class="line">save 60 10000</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;分别表示900秒（15分钟）内有1个更改，300秒（5分钟）内有10个更改以及60秒内有10000个更改。</p>
<ol>
<li>指定存储至本地数据库时是否压缩数据，默认为yes，Redis采用LZF压缩，如果为了节省CPU时间，可以关闭该选项，但会导致数据库文件变的巨大</li>
</ol>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">rdbcompression yes</div></pre></td></tr></table></figure>
<ol>
<li>指定本地数据库文件名，默认值为dump.rdb</li>
</ol>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">dbfilename dump.rdb</div></pre></td></tr></table></figure>
<ol>
<li>指定本地数据库存放目录</li>
</ol>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">dir ./</div></pre></td></tr></table></figure>
<ol>
<li>设置当本机为slav服务时，设置master服务的IP地址及端口，在Redis启动时，它会自动从master进行数据同步</li>
</ol>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">slaveof &lt;masterip&gt; &lt;masterport&gt;</div></pre></td></tr></table></figure>
<ol>
<li>当master服务设置了密码保护时，slav服务连接master的密码</li>
</ol>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">masterauth &lt;master-password&gt;</div></pre></td></tr></table></figure>
<ol>
<li>设置Redis连接密码，如果配置了连接密码，客户端在连接Redis时需要通过AUTH <password>命令提供密码，默认关闭</password></li>
</ol>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">requirepass foobared</div></pre></td></tr></table></figure>
<ol>
<li>设置同一时间最大客户端连接数，默认无限制，Redis可以同时打开的客户端连接数为Redis进程可以打开的最大文件描述符数，如果设置 maxclients 0，表示不作限制。当客户端连接数到达限制时，Redis会关闭新的连接并向客户端返回max number of clients reached错误信息</li>
</ol>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">maxclients 128</div></pre></td></tr></table></figure>
<ol>
<li>指定Redis最大内存限制，Redis在启动时会把数据加载到内存中，达到最大内存后，Redis会先尝试清除已到期或即将到期的Key，当此方法处理 后，仍然到达最大内存设置，将无法再进行写入操作，但仍然可以进行读取操作。Redis新的vm机制，会把Key存放内存，Value会存放在swap区</li>
</ol>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">maxmemory &lt;bytes&gt;</div></pre></td></tr></table></figure>
<ol>
<li>指定是否在每次更新操作后进行日志记录，Redis在默认情况下是异步的把数据写入磁盘，如果不开启，可能会在断电时导致一段时间内的数据丢失。因为 redis本身同步数据文件是按上面save条件来同步的，所以有的数据会在一段时间内只存在于内存中。默认为no</li>
</ol>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">appendonly no</div></pre></td></tr></table></figure>
<ol>
<li>指定更新日志文件名，默认为appendonly.aof</li>
</ol>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">appendfilename appendonly.aof</div></pre></td></tr></table></figure>
<ol>
<li>指定更新日志条件，共有3个可选值： </li>
</ol>
<ul>
<li><strong>no</strong>：表示等操作系统进行数据缓存同步到磁盘（快） </li>
<li><strong>always</strong>：表示每次更新操作后手动调用fsync()将数据写到磁盘（慢，安全） </li>
<li><strong>everysec</strong>：表示每秒同步一次（折衷，默认值）</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line">appendfsync everysec</div><div class="line">``` </div><div class="line"></div><div class="line">21. 指定是否启用虚拟内存机制，默认值为no，简单的介绍一下，VM机制将数据分页存放，由Redis将访问量较少的页即冷数据swap到磁盘上，访问多的页面由磁盘自动换出到内存中（在后面的文章我会仔细分析Redis的VM机制）</div><div class="line"></div><div class="line">```bash</div><div class="line">vm-enabled no</div></pre></td></tr></table></figure>
<ol>
<li>虚拟内存文件路径，默认值为/tmp/redis.swap，不可多个Redis实例共享</li>
</ol>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">vm-swap-file /tmp/redis.swap</div></pre></td></tr></table></figure>
<ol>
<li>将所有大于vm-max-memory的数据存入虚拟内存,无论vm-max-memory设置多小,所有索引数据都是内存存储的(Redis的索引数据 就是keys),也就是说,当vm-max-memory设置为0的时候,其实是所有value都存在于磁盘。默认值为0</li>
</ol>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">vm-max-memory 0</div></pre></td></tr></table></figure>
<ol>
<li>Redis swap文件分成了很多的page，一个对象可以保存在多个page上面，但一个page上不能被多个对象共享，vm-page-size是要根据存储的 数据大小来设定的，作者建议如果存储很多小对象，page大小最好设置为32或者64bytes；如果存储很大大对象，则可以使用更大的page，如果不 确定，就使用默认值</li>
</ol>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">vm-page-size 32</div></pre></td></tr></table></figure>
<ol>
<li>设置swap文件中的page数量，由于页表（一种表示页面空闲或使用的bitmap）是在放在内存中的，，在磁盘上每8个pages将消耗1byte的内存。</li>
</ol>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">vm-pages 134217728</div></pre></td></tr></table></figure>
<ol>
<li>设置访问swap文件的线程数,最好不要超过机器的核数,如果设置为0,那么所有对swap文件的操作都是串行的，可能会造成比较长时间的延迟。默认值为4</li>
</ol>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">vm-max-threads 4</div></pre></td></tr></table></figure>
<ol>
<li>设置在向客户端应答时，是否把较小的包合并为一个包发送，默认为开启</li>
</ol>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">glueoutputbuf yes</div></pre></td></tr></table></figure>
<ol>
<li>指定在超过一定的数量或者最大的元素超过某一临界值时，采用一种特殊的哈希算法</li>
</ol>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line"><span class="built_in">hash</span>-max-zipmap-entries 64</div><div class="line"><span class="built_in">hash</span>-max-zipmap-value 512</div></pre></td></tr></table></figure>
<ol>
<li>指定是否激活重置哈希，默认为开启（后面在介绍Redis的哈希算法时具体介绍）</li>
</ol>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">activerehashing yes</div></pre></td></tr></table></figure>
<ol>
<li>指定包含其它的配置文件，可以在同一主机上多个Redis实例之间使用同一份配置文件，而同时各个实例又拥有自己的特定配置文件</li>
</ol>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">include /path/to/local.conf</div></pre></td></tr></table></figure>

	

	
		<span class="different-posts"><a href="/2017/10/12/Redis/24. redis 配置/" onclick="window.history.go(-1); return false;">⬅️ Go back </a></span>

	

</article>

	</main>

	<footer class="footer">
	<div class="footer-content">
		
	      <div class="footer__element">
	<p>Hi there, <br />welcome to my Blog glad you found it. Have a look around, will you?</p>
</div>

	    
	      <div class="footer__element">
	<h5>Check out</h5>
	<ul class="footer-links">
		<li class="footer-links__link"><a href="/archives">Archive</a></li>
		
		  <li class="footer-links__link"><a href="/atom.xml">RSS</a></li>
	    
		<li class="footer-links__link"><a href="/about">about page</a></li>
		<li class="footer-links__link"><a href="/tags">Tags</a></li>
		<li class="footer-links__link"><a href="/categories">Categories</a></li>
	</ul>
</div>

	    

		<div class="footer-credit">
			<span>© 2017 失落的乐章 | Powered by <a href="https://hexo.io/">Hexo</a> | Theme <a href="https://github.com/HoverBaum/meilidu-hexo">MeiliDu</a></span>
		</div>

	</div>


</footer>



</body>

</html>
